package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.data.ResponseStausEnum;
import com.dongdongshop.pojo.GoodsVO;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.service.GoodService;
import com.dongdongshop.util.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description
 * @ClassName GoodsController
 * @Author RC
 * @date 2020.12.15 14:52
 */
@Controller
@RequestMapping("goods")
public class GoodsController {
    @Reference(timeout = 100000, check = false)
    private GoodService goodService;
    private static final Logger logger = LoggerFactory.getLogger(BrandController.class);

    @RequestMapping("getGoodsListAll")
    @ResponseBody
    public DataResult getGoodsListAll(@RequestParam(defaultValue = "1") Integer pageNumber, @RequestParam(defaultValue = "5") Integer pageSize, TbGoods tbGoods) {
        try {
            logger.info("进入商品审核方法");
            PageBean<GoodsVO> tbGoods1 = goodService.getGoodsListAll(pageNumber, pageSize, tbGoods);
            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(tbGoods1);

        } catch (Exception e) {
            logger.info("查询失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }

    //审核通过
    @RequestMapping("Approved")
    @ResponseBody
    public DataResult Approved(@RequestParam("ids[]")Long[] ids){
        try{
            logger.info("进入审核通过");
            goodService.getGoodsStatusById(ids);

            return DataResult.response(ResponseStausEnum.SUSSCESS);
        }catch (Exception e){
            logger.error("审核失败",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //驳回审核
    @RequestMapping("reject")
    @ResponseBody
    public DataResult reject(@RequestParam("ids[]")Long[] ids){
        try{
            logger.info("驳回审核");
            goodService.rejectGoodsStatusById(ids);

            return DataResult.response(ResponseStausEnum.SUSSCESS);
        }catch (Exception e){
            logger.error("审核失败",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //是否删除
    @RequestMapping("deleteBath")
    @ResponseBody
    public DataResult deleteBath(@RequestParam("ids[]")Long[] ids){
        try{
            logger.info("删除");
            goodService.deleteBath(ids);

            return DataResult.response(ResponseStausEnum.SUSSCESS);
        }catch (Exception e){
            logger.error("审核失败",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }

}
